import { deconstructEvent } from "../../hooks/deconstructEvent";
import http from "../../utils/http";
// pages/fav/fav.ts

Page({
  data: {
    active: 0,
    type: "school",
    a: ['billboard', 'blurb', 'major', 'school', 'vodeo'],
    b: ['billboard', 'blurb', 'major', 'school', 'vodeo'],
    collect_billboard_data: [],
    collect_blurb_data: [],
    collect_major_data: [],
    collect_school_data: [],
    collect_vodeo_data: [],
  },
  onNavChange(e) {
    this.setData({
      active: e.detail.index
    })
  },

  // [billboard,blurb,major,school,vodeo]
  get_fav_list() {
    http.get('/get/collect/').then(res => {
      // this.setData({ })
      const { type } = this.data
      console.log(res['collect_' + type + '_data']);
      const {
        // collect_billboard_data,
        //   collect_blurb_data,
        collect_major_data,
        collect_school_data
        //   collect_vodeo_data
      } = res
      this.setData({
        collect_major_data,
        collect_school_data
      })
      console.log(this.data.collect_major_data[0]);
    })
  },
  getDetails(e) {
    const { nid, url } = deconstructEvent(e)
    // /get/major/
    http.get("/get/" + url + "/", {
      nid
    }).then((res) => {
      console.log(res);
      const query: String = JSON.stringify(res)
      wx.navigateTo({
        url: "/pages/article/article" + "?" + "data=" + encodeURIComponent(query)
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.get_fav_list()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})